/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import Bean.Barang_Konsumen;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Yohanes Beny P
 */
@WebServlet(urlPatterns = {"/KonfirmasiUpdate"})
public class KonfirmasiUpdate extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, ParseException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String status = request.getParameter("status");
        String resi = request.getParameter("resi");
        String tgl_t = request.getParameter("tgl_terima");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = sdf.parse(tgl_t);
        } catch (ParseException ex) {
            Logger.getLogger(KonfirmasiUpdate.class.getName()).log(Level.SEVERE, null, ex);
        }

        String tgl = sdf.format(date);
        Bean.Barang_Konsumen bk = new Barang_Konsumen();
        try {
            bk.updateStatus(resi, status);
        } catch (SQLException ex) {
            Logger.getLogger(KonfirmasiUpdate.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            bk.updateTglTerima(resi, tgl_t);
        } catch (SQLException ex) {
            Logger.getLogger(KonfirmasiUpdate.class.getName()).log(Level.SEVERE, null, ex);
        }

        out.println("<html>");
        out.println("<head>");
        out.println("<title>Update Pengiriman Barang</title>");
        out.println("<link href=\"css/style.css\" rel=\"stylesheet\" type=\"text/css\"/>");
        out.println("</head>");
        out.println("<body id=\"home\">");
        out.println("<div id=\"wrapper\">");
        out.println("<center>");
        out.println("</br>");
        out.println("<center><img src=\"image/header.png\" width=\"600\" height=\"100\"/></center>");
        out.println("<h1 align='right'> <a href=\"../HomeCabang.jsp\"><img src=\"image/btn_home.png\" width=\"100\" height=\"40\"/></a>");
        out.println(" <a href=\"../FilterLogout\"><img src=\"image/logout.png\" width=\"100\" height=\"40\"/></a></h1>");
        out.println("</br></br><h2><b><font color=\"black\" face=\"Verdana\">PROSES KONFIRMASI BERHASIL....!!!</font></b></h2></br>");
        out.println("<form action=\"KantorCabang/TerimaUpdatePengiriman.jsp\"><input type=\"submit\" name=\"submit\" value=\"KEMBALI\"/></form>");
        out.println("</center>");
        out.println("</div>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (ParseException ex) {
            Logger.getLogger(KonfirmasiUpdate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (ParseException ex) {
            Logger.getLogger(KonfirmasiUpdate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
